package org.linlinjava.litemall.wx.controller;

import org.linlinjava.litemall.wx.annotation.LogAnno;
import org.linlinjava.litemall.wx.service.WxGoogleAuthService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.security.GeneralSecurityException;

/**
 * wx谷歌身份验证控制器
 *
 * @author yliyun
 * @date 2022/09/14
 */
@RestController
@RequestMapping("/wx/google/auth")
@Validated
public class WxGoogleAuthController {

    /**
     * 谷歌身份验证服务
     */
    @Autowired
    private WxGoogleAuthService googleAuthService;

    /**
     * 登录
     *
     * @param idTokenString id标记字符串
     * @param request       请求
     * @return {@link Object}
     * @throws GeneralSecurityException 一般安全例外
     * @throws IOException              ioexception
     */
    @PostMapping("login")
    @LogAnno
    public Object login(@RequestParam String idTokenString, HttpServletRequest request) throws GeneralSecurityException, IOException {
        return googleAuthService.login(idTokenString,request);
    }
}
